package cn.sc.summer.admin.notifier;

import de.codecentric.boot.admin.server.domain.events.InstanceEvent;
import de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent;
import de.codecentric.boot.admin.server.notify.Notifier;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

/**
 * 类名：服务注册新实例通知
 *
 * @author a-xin
 * @date 2024/3/27 11:46
 */
@Slf4j
@Component
public class AppRegistryNotifier implements Notifier {

    @NonNull
    @Override
    public Mono<Void> notify(@NonNull InstanceEvent event) {
        return Mono.fromRunnable(() -> {
            if (event instanceof InstanceRegisteredEvent) {
                InstanceRegisteredEvent re = (InstanceRegisteredEvent) event;
                log.error("==> The {} starts a new instance，instance id = {}，instance ip: {}", re.getRegistration().getName(),
                        re.getInstance(), re.getRegistration().getServiceUrl());
            }
        });
    }

}
